package com.google.code.memoriesalbum;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.io.IOUtils;

import com.google.code.memoriesalbum.util.Constants;

/**
 * @author shin1ogawa
 */
public class GetAlbumList {

	/**
	 * Production環境にアルバム一覧を取得するリクエストを発行する。
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("id:");
		String id = input.readLine();
		System.out.println("token:");
		String token = input.readLine();

		URL url = new URL("http://photo-storage.appspot.com/albums/");
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		System.out.println(Constants.X_HEADER_ID + ": " + id);
		connection.addRequestProperty(Constants.X_HEADER_ID, id);
		System.out.println(Constants.X_HEADER_TOKEN + ": " + token);
		connection.addRequestProperty(Constants.X_HEADER_TOKEN, token);

		System.out.println("responseCode=" + connection.getResponseCode());
		InputStream inputStream = connection.getInputStream();
		String result = IOUtils.toString(inputStream);
		IOUtils.closeQuietly(inputStream);
		System.out.println("responseBody ---");
		System.out.println(result);
	}

}
